<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>reflect_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_debug_reflect_test.js.html">reflect_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.debug.reflectTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.debug.reflectTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.debug.reflect&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line21"></a>
<a name="line22"></a>var typeOf = goog.debug.reflect.typeOf;
<a name="line23"></a>var className = goog.debug.reflect.className;
<a name="line24"></a>
<a name="line25"></a>function testBasicTypes() {
<a name="line26"></a>  assertEquals(&#39;undefined&#39;, typeOf(undefined));
<a name="line27"></a>  assertEquals(&#39;null&#39;, typeOf(null));
<a name="line28"></a>  assertEquals(&#39;boolean&#39;, typeOf(false));
<a name="line29"></a>  assertEquals(&#39;number&#39;, typeOf(0));
<a name="line30"></a>  assertEquals(&#39;string&#39;, typeOf(&#39;&#39;));
<a name="line31"></a>
<a name="line32"></a>  assertUndefined(className(undefined));
<a name="line33"></a>  assertUndefined(className(null));
<a name="line34"></a>  assertUndefined(className(false));
<a name="line35"></a>  assertUndefined(className(0));
<a name="line36"></a>  assertUndefined(className(&#39;&#39;));
<a name="line37"></a>}
<a name="line38"></a>
<a name="line39"></a>function testWrapperTypes() {
<a name="line40"></a>  assertEquals(&#39;Boolean&#39;, typeOf(new Boolean(false)));
<a name="line41"></a>  assertEquals(&#39;Number&#39;, typeOf(new Number(0)));
<a name="line42"></a>  assertEquals(&#39;String&#39;, typeOf(new String(&#39;&#39;)));
<a name="line43"></a>
<a name="line44"></a>  assertEquals(&#39;Boolean&#39;, className(Boolean));
<a name="line45"></a>  assertEquals(&#39;Number&#39;, className(Number));
<a name="line46"></a>  assertEquals(&#39;String&#39;, className(String));
<a name="line47"></a>}
<a name="line48"></a>
<a name="line49"></a>function testBuiltInTypes() {
<a name="line50"></a>  assertEquals(&#39;Array&#39;, typeOf([]));
<a name="line51"></a>  assertEquals(&#39;Date&#39;, typeOf(new Date));
<a name="line52"></a>  assertEquals(&#39;Error&#39;, typeOf(new Error));
<a name="line53"></a>  assertEquals(&#39;Function&#39;, typeOf(function() {}));
<a name="line54"></a>  assertEquals(&#39;Object&#39;, typeOf({}));
<a name="line55"></a>  assertEquals(&#39;RegExp&#39;, typeOf(/./));
<a name="line56"></a>
<a name="line57"></a>  assertEquals(&#39;Array&#39;, className(Array));
<a name="line58"></a>  assertEquals(&#39;Date&#39;, className(Date));
<a name="line59"></a>  assertEquals(&#39;Error&#39;, className(Error));
<a name="line60"></a>  assertEquals(&#39;Object&#39;, className(Object));
<a name="line61"></a>}
<a name="line62"></a>
<a name="line63"></a>function testGoogProvidedTypes() {
<a name="line64"></a>  // Force type map reinitialization with the goog.provided types.
<a name="line65"></a>  delete goog.debug.reflect.typeMap_;
<a name="line66"></a>
<a name="line67"></a>  goog.provide(&#39;x.a&#39;);
<a name="line68"></a>  x.a = function() {};
<a name="line69"></a>  x.a.b = function() {};
<a name="line70"></a>
<a name="line71"></a>  assertEquals(&#39;Object&#39;, typeOf(x));
<a name="line72"></a>  assertEquals(&#39;x.a&#39;, typeOf(new x.a));
<a name="line73"></a>  assertEquals(&#39;Object&#39;, typeOf(new x.a.b));
<a name="line74"></a>
<a name="line75"></a>  assertUndefined(className(x));
<a name="line76"></a>  assertEquals(&#39;x.a&#39;, className(x.a));
<a name="line77"></a>  assertUndefined(className(x.a.b));
<a name="line78"></a>}
<a name="line79"></a>
<a name="line80"></a>function testUnregisteredTypes() {
<a name="line81"></a>  var oldIE = goog.userAgent.IE &amp;&amp; !goog.userAgent.isVersionOrHigher(8);
<a name="line82"></a>  assertEquals(oldIE ? &#39;ActiveXObject&#39; : &#39;HTMLDocument&#39;, typeOf(document));
<a name="line83"></a>
<a name="line84"></a>  var expectedTypeOfBody = oldIE ? &#39;ActiveXObject&#39; : &#39;HTMLBodyElement&#39;;
<a name="line85"></a>  assertEquals(expectedTypeOfBody, typeOf(document.body));
<a name="line86"></a>
<a name="line87"></a>  var expectedTypeOfWindow = &#39;Window&#39;;
<a name="line88"></a>  if (goog.userAgent.WEBKIT || goog.userAgent.OPERA) {
<a name="line89"></a>    // Note: window.constructor.name is &#39;DOMWindow&#39; in Chrome but the type
<a name="line90"></a>    // DOMWindow is not exposed to JavaScript.
<a name="line91"></a>    expectedTypeOfWindow = &#39;Object&#39;;
<a name="line92"></a>  }
<a name="line93"></a>  if (oldIE) {
<a name="line94"></a>    expectedTypeOfWindow = &#39;ActiveXObject&#39;;
<a name="line95"></a>  }
<a name="line96"></a>  assertEquals(expectedTypeOfWindow, typeOf(window));
<a name="line97"></a>}
</pre>


</body>
</html>
